from drf_haystack.serializers import HaystackSerializer
from rest_framework import serializers

from goods.models import SKU
from goods.search_indexes import SKUIndex


class SKUSerializer(serializers.ModelSerializer):
    """返回商品信息序列化器"""

    class Meta:
        model = SKU
        fields = ['id', 'name', 'price', 'default_image_url', 'comments']


class SKUIndexSerializer(HaystackSerializer):
    """商品搜索索引结果序列化器"""

    class Meta:
        index_classes = [SKUIndex]
        fields = ['text', 'name', 'id', 'price', 'default_image_url', 'comments']
